package com.version1_4.controller;

import com.alibaba.fastjson.JSONObject;
import com.version1_2.controller.PageController1_2;
import com.version1_3.controller.PageController1_3;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * Created by reeveslee on 16/4/27.
 */
@Controller
public class PageController1_4 {
    private static final Logger LOGGER = Logger.getLogger(PageController1_4.class);

    @Autowired
    private PageController1_3 pageController13;

    @Autowired
    private PageController1_2 pageController12;


    /**
     * 登录用户获取主页面信息
     */
    @RequestMapping(value = "/version1_4/page/mainPage/{firstType}/{userId}/{pageNumber}/{cacheTag}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getMainPage(@PathVariable("firstType") int firstType, @PathVariable("userId") int userId, @PathVariable("pageNumber") int pageNumber, @PathVariable("cacheTag") boolean cacheTag) {
        return pageController13.getMainPage(firstType, userId, pageNumber, cacheTag);
    }

    /**
     * 未登陆用户获取主页面信息
     */
    @RequestMapping(value = "/version1_4/page/mainPageNoLogin/{firstType}/{pageNumber}/{cacheTag}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getMainPageNoLogin(@RequestBody JSONObject jsonObject, @PathVariable("firstType") int firstType, @PathVariable("pageNumber") int pageNumber, @PathVariable("cacheTag") boolean cacheTag) {
        return pageController13.getMainPageNoLogin(jsonObject, firstType, pageNumber, cacheTag);
    }

    /**
     * 获取三级分类界面信息
     */
    @RequestMapping(value = "/version1_4/page/thirdPage/{thirdTypeId}/{pageNumber}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getThirdPage(HttpServletRequest request, @PathVariable("thirdTypeId") int thirdTypeId,
                               @PathVariable("pageNumber") int pageNumber)
            throws UnsupportedEncodingException {
        return pageController13.getThirdPage(request, thirdTypeId, pageNumber);
    }


    /**
     * 获取正文其他信息
     */
    @RequestMapping(value = "/version1_4/page/getPageOtherInfo/{userId}/{pageId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getPageOtherInfo(@PathVariable("pageId") int pageId, @PathVariable("userId") int userId) {
        return pageController13.getPageOtherInfo(pageId, userId);
    }

    /**
     * 获取正文界面信息,增加积分记录
     */
    @RequestMapping(value = "/version1_4/page/getPageInfo/{pageId}/{userId}", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String getPageInfo(HttpServletRequest request, @PathVariable("pageId") int pageId, @PathVariable("userId") int userId) {
        return pageController13.getPageInfo(request, pageId, userId);
    }

    /**
     * 记录文章被转发(分享),新增积分功能
     */
    @RequestMapping(value = "/version1_4/page/transmit/{pageId}/{userId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String doTransmitCount(@PathVariable("pageId") int pageId, @PathVariable("userId") int userId) {
        return pageController13.doTransmitCount(pageId, userId);
    }

    /**
     * 配合诸葛IO-获取文章相关信息
     */
    @RequestMapping(value = "/version1_4/page/getArticleDetail/{pageId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getArticleDetail(@PathVariable("pageId") int pageId) {
        return pageController13.getArticleDetail(pageId);
    }

    /**
     * 获取推送文章信息
     */
    @RequestMapping(value = "/version1_4/page/pushArticleInfo/{key}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getPushArticleInfo(@PathVariable("key") String key, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        return pageController13.getPushArticleInfo(key, response);
    }

    /**
     * 获取正文界面信息
     * 增加缓存清除功能 3.25
     */
    @RequestMapping(value = "/version1_4/page/getPageInfo/{pageId}", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String getPageInfo(HttpServletRequest request, @PathVariable("pageId") int pageId) {
        return pageController12.getPageInfo(request, pageId);
    }

    /**
     * 获取文章评论列表
     */
    @RequestMapping(value = "/version1_4/page/getCommentList/{userId}/{pageId}/{pageNumber}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getCommentList(@PathVariable("userId") int userId,
                                 @PathVariable("pageId") int pageId,
                                 @PathVariable("pageNumber") int pageNumber)
            throws UnsupportedEncodingException {
        return pageController12.getCommentList(userId, pageId, pageNumber);
    }

    /**
     * 记录文章被阅读
     */
    @RequestMapping(value = "/version1_4/page/read/{pageId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String doRead(@PathVariable("pageId") int pageId) {
        return pageController12.doRead(pageId);
    }

    /**
     * 搜索文章
     */
    @RequestMapping(value = "/version1_4/page/search/{key}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String searchPage(@PathVariable("key") String key) throws UnsupportedEncodingException {
        return pageController12.searchPage(key);
    }

    /**
     * 记录文章被转发(分享)
     */
    @RequestMapping(value = "/version1_4/page/transmit/{pageId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String doTransmitCount(@PathVariable("pageId") int pageId) {

        return pageController12.doTransmitCount(pageId);
    }

    /**
     * 文章内容评价水文好文
     */
    @RequestMapping(value = "/version1_4/page/pageContentComment/{userId}/{pageId}/{commentType}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String pageContentComment(@PathVariable("userId") int userId, @PathVariable("pageId") int pageId, @PathVariable("commentType") int commentType) {
        return pageController12.pageContentComment(userId, pageId, commentType);
    }

    /**
     * 获取某条评论的回复信息
     */
    @RequestMapping(value = "/version1_4/page/comReply/{commentId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getCommentReply(@PathVariable("commentId") int commentId) throws UnsupportedEncodingException {

        /**
         * 返回信息：comReplyStr
         * 格式：[{"replyerName":"","replyerPhoto":"","replyDate":"","replyContent":""}...]
         */
        return pageController12.getCommentReply(commentId);
    }

    /**
     * 对文章的评论进行点赞
     */
    @RequestMapping(value = "/version1_4/page/comPraise", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String pageComPraise(HttpServletRequest request, @RequestBody JSONObject jsonObject)
            throws UnsupportedEncodingException {
        return pageController12.pageComPraise(request, jsonObject);
    }

    /**
     * 新增文章评论,增加积分记录
     */
    @RequestMapping(value = "/version1_4/page/addComment", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String pageComment(HttpServletRequest request, @RequestBody JSONObject jsonObject) throws UnsupportedEncodingException {
        return pageController12.pageComment(request, jsonObject);
    }

    /**
     * 在文章中进行反馈
     */
    @RequestMapping(value = "/version1_4/page/postComInPage", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String postComInPage(HttpServletRequest request, @RequestBody JSONObject jsonObject) throws UnsupportedEncodingException {
        return pageController12.postComInPage(request, jsonObject);
    }

}
